package elastic

import (
	"github.com/spf13/viper"
)

type UsersModel struct {
	Uid       int64  `json:"uid"`
	Citycode  string `json:"citycode"`
	Status    int    `json:"status"`
	Name      string `json:"name"`
	Shortname string `json:"shortname"`
}

func UsersClient() (*Search, error) {
	var index, typ, pk, mapping string
	index = "yy_test_user"
	typ = "default"
	pk = "id"
	mapping = `
	{
		"settings": {
			"index.number_of_shards": 1,
			"index.number_of_replicas": 3,
			"index.store.type": "mmapfs",
			"index.store.preload": [
				"*"
			]
		},
		"mappings": {
			"default": {
				"properties": {
					"uid": {
						"type": "long",
						"index": true,
						"store": true
					},
					"citycode": {
						"type": "keyword",
						"index": true,
						"store": true
					},
					"status": {
						"type": "integer",
						"index": true,
						"store": true
					},
					"name": {
						"type": "keyword",
						"index": true,
						"store": true,
						"copy_to": "keyword"
					},
					"shortname": {
						"type": "keyword",
						"index": true,
						"store": true,
						"copy_to": "keyword"
					},
					"keyword": {
						"type": "text",
						"index": true,
						"store": true,
						"analyzer": "text_ik_i_index",
						"search_analyzer": "text_ik_i_query",
						"search_quote_analyzer": "text_ik_i_index"
					}
				}
			}
		}
	}
	`

	dsn := viper.GetStringSlice("elastic.url")
	return NewClient(index, pk, typ, mapping, dsn...)
}
